using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//存储所有UI信息，并可以创建或者销毁UI
public class UIManager
{
    //存储所有UI信息的字典，每一个UI信息都会对应一个gameObject
    private Dictionary<UIType, GameObject>dicUI;
	public UIManager()
    {
        //初始化
         dicUI = new Dictionary<UIType, GameObject>();   
    }
    //获取UI对象
    public GameObject GetSingleUI(UIType type)
    {
        GameObject parent = GameObject.Find("Canvas");
        if(!parent)
        {
            Debug.LogError("Canvas not exist");
            return null;
        }
        if(dicUI.ContainsKey(type))
            return dicUI[type];
        GameObject ui = GameObject.Instantiate(Resources.Load<GameObject>(type.Path),parent.transform);
        ui.name=type.Name;
        return ui;
    }

    //销毁一个UI对象
	public void DestroyUI(UIType type)
    {
        if(dicUI.ContainsKey(type))
        {
            DestroyUI(type);
            dicUI.Remove(type);
        }
    }
}